import React from "react";
import View from "../base/View";
import defaultData from "./data";
import NewInputNumber from '../../../../common/InputNumber';
import { WeaLocaleProvider } from "ecCom";

const formatMultiLang = WeaLocaleProvider.formatMultiLang;

export default class NumberView extends View {
  renderContent(data, value) {
    const { data: { precision, isPrecision, type } } = this.props;
    const { placeholder } = data;
    const prec = Math.min(precision || 0, 6);
    const isFloat = type == '1';
    const isPrecisonChecked = Boolean(Number(isPrecision));
    const step = isFloat ? 1 : isPrecisonChecked ? Math.pow(10, -prec).toFixed(prec) : Math.pow(10, -6).toFixed(6);
    
    return (
      <div className='wea-edc-input-conatiner wea-input-normal'>
        <NewInputNumber ecId={`${this && this.props && this.props.ecId || ''}_NewInputNumber@m2b2cl`}
          key={value} 
          defaultValue={value} 
          onBlur={value => {this.handleValueChange(value)}} 
          step={step} 
          min={-999999999}
          max={999999999}
          placeholder={formatMultiLang(placeholder)}
          type='number'
        />
      </div>
    );
  }
}

NumberView.defaultProps = {
  data: defaultData,
  value: ''
};